<?php
namespace Home\Model;
use Think\Model;
class MessageModel extends Model {
	protected $tableName = 'message';
	/**
	 * 发送消息
	 * @param number $send_id
	 * @param number $receive_id
	 * @param string $message
	 * @return boolean
	 */
	public function send($send_id=0,$receive_id=0,$message='',$type=''){
		if(empty($send_id) || empty($receive_id) || empty($message) || empty($type)){
			return false;
		}
		$d = array(
			'send_id'		=> $send_id,
			'receive_id'	=> $receive_id,
			'message'		=> $message,
			'send_time'		=> $_SERVER[REQUEST_TIME],
			'mode'			=> 0,
			'type'			=> $type
		);
		//print_r($d);
		return $this->data($d)->add();
		//echo $this->getLastSql();
	}
	/**
	 * 获取消息
	 * @param number $send_id
	 * @param number $receive_id
	 * @param number $start
	 * @param number $end
	 */
	public function getMessage($send_id=0,$receive_id=0,$start=0,$end=10){
		$d = array(
			'mode' => 1,
			'send_id' => $send_id,
			'receive_id' => $receive_id,
			'mode' => 0
		);
		$this->where($w)->save($d);
		

		$w = array(
			'send_id' => $send_id,
			'receive_id' => $receive_id,
			'mode' => 1
		);
		return $this->where($w)->order('send_time desc')->limit("$start,$end")->select();		
	}
	/**
	 * 仅获取未读消息
	 * @param number $send_id
	 * @param number $receive_id
	 */
	public function getUnreadMessage($send_id=0,$receive_id=0){

	}
	public function del($message_id=0){

	}
}
?>